/****************************************************************************

	COPYRIGHT(C) MAXSI SOFTWARE, JONAS 'SORTIE' TERMANSEN 2008, 2009, 2010

    This file is part of Maxsi Engine.

    Maxsi Engine is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Maxsi Engine is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Maxsi Engine. If not, see <http://www.gnu.org/licenses/>.

	*/ #include "MaxsiEngineContributors.h" /*

	If you modify this file, please enter your name below and provide contact
	information in MaxsiEngineContributors.h. For more information please see
	MaxsiEngineContributors.h.
	
	Contributors to this file:

	- Jonas 'Sortie' Termansen
	- [your name here]

	MaxsiEngine.dll
	A linkable version of Maxsi Engine

	MaxsiNetworking.cpp
	Multithreaded Networking

****************************************************************************/

#ifndef MaxsiNetworking_H
#define MaxsiNetworking_H

#define	MSG_NETWORK_EVENT	0x00010000	// Should be above all Windows-generated messages!

namespace MaxsiEngine
{
	struct HTTPParser_Struct
	{
		size_t	Read;
		size_t	AddLenght;
		size_t	OutLenght;
		size_t	InLenght;
		List	Headers;
		char*	Add;
		char*	Out;
		char*	In;
		int		ResponseCode;
		int		Step;
		size_t	ChunkBegin;
		size_t	ChunkLenght;
		bool	ShouldDisconnect;
	};

	//struct NetworkingProgress_Struct
	//{
	//	char*	PureBuffer;
	//	size_t	PureBuffer_Len;
	//	char*	ParsedBuffer;
	//	size_t	ParsedBuffer_Len;
	//};

	typedef HTTPParser_Struct (__cdecl* NetworkingProgress_Type)(HTTPParser_Struct);

	LINK	HTTPParser_Struct	ConnectAndSendHTTPQuery(char* Buffer, size_t BufferLen, char* HostName, NetworkingProgress_Type ProgressFunc = 0);
	//LINK	char*				ParseHTTPResponse(char* Buffer, size_t BufferLen, size_t* ResponseSize, NetworkingProgress_Type ProgressFunc = 0);
	LINK	HTTPParser_Struct	ParseHTTPResponse(HTTPParser_Struct Parser);
	LINK	bool				DeleteHTTPParser_Struct(HTTPParser_Struct Parser);
	LINK	IP					HostToIp(const char* Host);
	LINK	int					SendHTTPQuery(HWND Networking_Window, char* Buffer, size_t BufferLen, SOCKET Sock, ProgressFunc_Type ProgressFunc = 0);
	LINK	BOOL				HTTPParse_ShouldClose(char* Buffer, int BufferSize);
	LINK	char*				GetHostFromURI(char* URI);
	LINK	char*				GetResourceFromURI(char* URI);
	LINK	HTTPParser_Struct	UploadFile(char* Host, char* Resource, char* FileName, char* Buffer, size_t BufferLen, NetworkingProgress_Type ProgressFunc = 0);
}
#endif
